package frog.lazy.framework.core.exception;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class BizException extends RuntimeException{
    private int code;
    private String msg;

    private BizException(int code, String msg, Throwable cause){
        super(msg, cause);
        this.code = code;
        this.msg = msg;
    }

    private BizException(int code, String msg){
        this(code, msg, null);
        this.code = code;
        this.msg = msg;
    }

    /**
     * 错误
     */
    public static final int FAIL = 400;

    /**
     * 权限检查 未登录异常
     */
    public static final int NO_LOGIN = 403;

    /**
     * 异常
     */
    public static final int ERROR = 500;

    public static BizException noLogin(String msg){
        return new BizException(NO_LOGIN, msg);
    }

    public static BizException fail(String msg){
        return new BizException(FAIL,msg);
    }
    public static BizException fail(String msg, Throwable cause){
        return new BizException(FAIL,msg, cause);
    }

    public static BizException error(String msg){
        return new BizException(ERROR,msg);
    }

}
